package LEX;

import java.util.concurrent.locks.Lock;

public class LanguageExtensions {
    public static void lock(Lock lockObject, Runnable action)
    {
        lockObject.lock();
        try
        {
            action.run();
        }finally
        {
            lockObject.unlock();
        }
    }

    @SuppressWarnings("unchecked")
    public static <E extends Throwable> void throwUnchecked(Throwable e) throws E {
        throw (E) e;
    }

    public static <T> T as(Object o, Class<T> targetType) {
        if (o == null)
        {
            return null;
        }
        if (targetType.isAssignableFrom(o.getClass())) {
            return (T)o;
        }
        return null;
    }
}
